Skip to main content
Open in Colab Open in Kaggle

Installation

First, let’s install the necessary packages to run this tutorial.
Now, test the installation. If there’s no error message, we are ready to go.
📘 Info There are over 50,000 openly available datasets on Hugging Face Datasets. Some datasets are gated and can only be downloaded if you have a user credential.

Load Dataset

The Hugging Face datasets package provides an easy interface to load any datasets from the Hugging Face platform. On top of the package, fastdup provides a wrapper class FastdupHFDataset as a connector to ensure the datasets package works seamlessly within fastdup. The FastdupHFDataset class works the same way as the load_dataset method. You can import the wrapper class and specify the name of the Hugging Face Datasets repository as the first argument. In this example, we load the Tiny ImageNet dataset which contains 100,000 images of 200 classes (500 for each class) downsized to 64×64 colored images. Each class has 500 training images, 50 validation images, and 50 test images. In the following code, we load the train split of the Tiny ImageNet dataset.
👍 Tip Optional parameters for the FastdupHFDataset class:
  • split - Which split to download. Default: 'train'.
  • img_key- The key value for the dataset column containing images. Default: 'image'.
  • label_key - The key value for the dataset column containing labels. Default: 'label'.
  • cache_dir - Where to cache the downloaded dataset. Default: '/root/.cache/huggingface/datasets/'
  • jpg_save_dir - Which folder to store the jpg images. Default: 'jpg_images'
  • reconvert_jpg- Flag to force reconversion of images from .parquet to .jpg. Default: False
See implementation for details.
Now, let’s inspect the dataset object.
Get the first element of the dataset.
Get the PIL image of the first element.
Get the label of the first element.
📘 Info You can also confirm the image and label of the first element by heading to the dataset page.

Run fastdup

Once loaded, we can now analyze the dataset in fastdup by passing in 2 properties of dataset into fastdup:
  • dataset.img_dir - Returns the folder directory where the jpg images are saved.
  • dataset.annotations- Returns aDataFrame of image and class labels.
Let’s run fastdup and pass indataset.img_dir and dataset.annotations as arguments.
Once completed, we can visualize the issues in fastdup galleries.

Duplicates

Let’s visualize the duplicates in a gallery.
To get a detailed DataFrame on the duplicates/near-duplicate found, use the similaritymethod.
We can get the number of duplicates/near-duplicates by filtering them on the distance score. A distance of 1.0 is an exact copy, and vice versa.

Outliers

Mislabels

Wrap Up

That’s it! We’ve just conveniently surfaced many issues with this dataset by running fastdup. By taking care of dataset quality issues, we hope this will help you train better models. Questions about this tutorial? Reach out to us on our Slack channel!

VL Profiler - A faster and easier way to diagnose and visualize dataset issues

The team behind fastdup also recently launched VL Profiler, a no-code cloud-based platform that lets you leverage fastdup in the browser. VL Profiler lets you find:
  • Duplicates/near-duplicates.
  • Outliers.
  • Mislabels.
  • Non-useful images.
Here’s a highlight of the issues found in the RVL-CDIP test dataset on the VL Profiler.
👍 Free Usage Use VL Profiler for free to analyze issues on your dataset with up to 1,000,000 images. Get started for free.
Not convinced yet? Interact with a collection of datasets like ImageNet-21K, COCO, and DeepFashion here. No sign-ups needed.